package com.zy.Conterller;

import com.baomidou.mybatisplus.extension.api.R;
import com.zy.pojo.Management;
import com.zy.pojo.mm;
import com.zy.service.ManService;
import com.zy.vo.ManagementVo;
import com.zy.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("/sys/role")
public class ManCont {
    @Resource
    private ManService manService;

    @GetMapping("/list")
    public ResultVo getUserList(ManagementVo managementVo) {
        return ResultVo.success(manService.getManagement(managementVo));

    }
    @GetMapping("/pagelist/{pageSize}/{pageNo}")
     public ResultVo getManage(@PathVariable Integer pageSize,@PathVariable Integer pageNo,ManagementVo managementVo){
        return ResultVo.success(manService.getPage(pageNo,pageSize,managementVo));
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody Management management, HttpSession session){
        if (management!=null){
            return ResultVo.fail("不能为空添加,请重新添加");
            
        }
        try{
            management.setUserDate(new Date());
            manService.add(management);
            return ResultVo.success("角色添加成功");
        }catch (Exception e){
            return ResultVo.fail("角色添加失败",e);
        }
    }
    @PostMapping("/update")
    public ResultVo update(@RequestBody Management management, HttpSession session){

            try{
                manService.update(management);

                return ResultVo.success("角色修改成功");
            }catch (Exception e){

                return ResultVo.fail("角色修改失败",e);
        }
    }
    @GetMapping("del/{id}")
    public ResultVo del(@PathVariable String id){
        try{
            manService.delete(Integer.parseInt(id));
            return ResultVo.success("删除成功！");
        }catch (Exception e){
            return ResultVo.fail("删除失败",e);
        }
    }
}